package com.example.java_gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManager {
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall = new ConcurrentHashMap<>();
    private ConcurrentHashMap<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>();

    //在线状态
    public void enterGameHall(int userId, WebSocketSession webSocketSession){
        gameHall.put(userId, webSocketSession);
    }

    //离线状态
    public void exitGameHall(int userId){
        gameHall.remove(userId);
    }

    //查找状态
    public WebSocketSession getSessionByHall(Integer userId){
        return gameHall.get(userId);
    }

    public void enterGameRoom(Integer userId, WebSocketSession webSocketSession){
        gameRoom.put(userId, webSocketSession);
    }

    public void exitGameRoom(Integer userId){
        gameRoom.remove(userId);
    }

    public WebSocketSession getSessionByRoom(Integer userId){
        return gameRoom.get(userId);
    }
}
